package org.apache.mina.common;

/**
 * Allocates {@link ByteBuffer}s and manages them. Please implement this
 * interface if you need more advanced memory management scheme.
 * 
 * 分配并管理ByteBuffer。如果你需要更多高级的内存管理计算，可以实现该接口。
 */
public interface ByteBufferAllocator {
    /**
     * Returns the buffer which is capable of the specified size.
     * 
     * 返回指定容量的buffer
     * 
     * @param capacity
     *            the capacity of the buffer
     * @param direct
     *            <tt>true</tt> to get a direct buffer, <tt>false</tt> to get a
     *            heap buffer. 返回直接缓冲器或堆缓冲器。
     */
    ByteBuffer allocate(int capacity, boolean direct);

    /**
     * Wraps the specified NIO {@link java.nio.ByteBuffer} into MINA buffer.
     * 
     * 将指定的NIO的ByteBuffer封装成MINA的buffer。
     */
    ByteBuffer wrap(java.nio.ByteBuffer nioBuffer);

    /**
     * Dispose of this allocator.
     * 
     * 销毁此分配器。
     */
    void dispose();
}
